package io.geekidea.boot.shop.controller.web;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.shop.dto.GradeLevelDto;
import io.geekidea.boot.shop.query.web.GradeLevelQuery;
import io.geekidea.boot.shop.service.base.api.GradeLevelService;
import io.geekidea.boot.shop.vo.web.GradeLevelVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 11个等级 控制器
 *
 * @author geekidea
 * @since 2024-10-27
 */
@Slf4j
@RestController
@Tag(name = "11个等级")
@RequestMapping("/admin/gradeLevel")
public class GradeLevelController {

    @Autowired
    private GradeLevelService gradeLevelService;

    /**
     * 添加11个等级
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加11个等级")
    @PostMapping("/addGradeLevel")
    @Permission("grade:level:add")
    public ApiResult addGradeLevel(@Valid @RequestBody GradeLevelDto dto) {
        log.info("添加11个等级：{}", dto);
        boolean flag = gradeLevelService.addGradeLevel(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改11个等级
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改11个等级")
    @PostMapping("/updateGradeLevel")
    @Permission("grade:level:update")
    public ApiResult updateGradeLevel(@Valid @RequestBody GradeLevelDto dto) {
        log.info("修改11个等级：{}", dto);
        boolean flag = gradeLevelService.updateGradeLevel(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除11个等级
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除11个等级")
    @PostMapping("/deleteGradeLevel/{id}")
    @Permission("grade:level:delete")
    public ApiResult deleteGradeLevel(@PathVariable Long id) {
        log.info("删除11个等级：{}", id);
        boolean flag = gradeLevelService.deleteGradeLevel(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取11个等级详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取11个等级详情")
    @PostMapping("/getGradeLevel/{id}")
    @Permission("grade:level:info")
    public ApiResult<GradeLevelVo> getGradeLevel(@PathVariable Long id) {
        log.info("获取11个等级详情：{}", id);
        GradeLevelVo gradeLevelVo = gradeLevelService.getGradeLevelById(id);
        return ApiResult.success(gradeLevelVo);
    }

    /**
     * 获取11个等级分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取11个等级分页列表")
    @PostMapping("/getGradeLevelPage")
    @Permission("grade:level:page")
    public ApiResult<GradeLevelVo> getGradeLevelPage(@Valid @RequestBody GradeLevelQuery query) {
        log.info("获取11个等级分页列表：{}", query);
        Paging<GradeLevelVo> paging = gradeLevelService.getGradeLevelPage(query);
        return ApiResult.success(paging);
    }

}
